/**
 * Copyright (c) 2010 BullionXpress.com,
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */


package com.bullionxpress.shared.model;

import java.io.Serializable;
import com.bullionxpress.server.application.ServerGlobals;
import com.bullionxpress.server.application.ServerGlobals;
import com.bullionxpress.shared.util.Utility;

/**
 *
 * @author BullionXpress.com
 */
public class Position implements Serializable {
    public static long NOT_SET = -1;
    private String id = null;
    private long units = 0;
    private double entryPrice = 0;
    private Instrument instrument = null;
    private Account account = null;

    public Position()
    {
        id = "P" + Long.toHexString(Utility.generateId());
    }

    public Position(Instrument instrument)
    {
        this();
        this.instrument = instrument;
    }

    /**
     * @return the units
     */
    public long getUnits() {
        return units;
    }

    /**
     * @param units the units to set
     */
    public void setUnits(long units) {
        this.units = units;
    }

    /**
     * @return the price
     */
    public double getEntryPrice() {
        return entryPrice;
    }

    /**
     * @param price the price to set
     */
    public void setEntryPrice(double price) {
        this.entryPrice = price;
    }

    /**
     * @return the instrument
     */
    public Instrument getInstrument() {
        return instrument;
    }

    /**
     * @param instrument the instrument to set
     */
    public void setInstrument(Instrument instrument) {
        this.instrument = instrument;
    }

    /**
     * @return the id
     */
    public String getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * @return the account
     */
    public Account getAccount() {
        return account;
    }

    /**
     * @param account the account to set
     */
    public void setAccount(Account account) {
        this.account = account;
    }

    public String toString()
    {
        String aid = "";
        if( account == null ) {
            aid = "null";
        } else {
            aid = account.getId();
        }
        String str = "position:" + id + " " + units + " " + entryPrice + " " + instrument + " accountID#" + aid;
        if( !ServerGlobals.verbose) {
            str = "";
        }

        return str;
    }
}
